﻿///////////////////////////////////////////////////////////////////////////////
// File:        EchoServer.hpp
// Author:      671643387@qq.com
// Description:
///////////////////////////////////////////////////////////////////////////////

#ifndef ECHO_SERVER_ECHOSERVER_HPP_
#define ECHO_SERVER_ECHOSERVER_HPP_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <boost/unordered_map.hpp>
#include <boost/shared_array.hpp>
#include <nio/net/Server.hpp>

class EchoServer
{
public:
    EchoServer(void);
    ~EchoServer(void);

    bool open(std::string addr, int port, int backlog, int threads
        , bool useBuffSet, unsigned int sndBufSize, unsigned int rcvBufSize
        , unsigned int isSize, unsigned int osSize);
    void close(void);
    void run(void);

private:
    void onConnectionEstablised(nio::net::ConnectionPtr& conn);

    void onConnectionReadable(nio::net::Connection& conn, nio::net::ConnectionInputStream& is);
    void onConnectionWritable(nio::net::Connection& conn, nio::net::ConnectionOutputStream& os);
    void onConnectionError(nio::net::Connection& conn);
    void onConnectionHeartbeat(nio::net::Connection& conn);
    void onConnectionClose(nio::net::Connection& conn);

    void dumpConfig(void);
    void dumpStatics(void);

private:
    nio::net::Server server_;
};

#endif //ECHO_SERVER_ECHOSERVER_HPP_
